<?php

	/*
	*	数据表模型类
	*	封装有对数据表针对性的操作
	*/

	require_once(ROOT_PATH . 'frame/core/lib/db/class_Db.php');

	class DataTableModel {

	    private $db;

	    public function __construct() {

	        $this->db = new Db();

        }
		public function insert($keyList, $valueList) {
			
			$tempKeyList = $keyList;
			
			$sql = "insert into resume_info(";
			
			while(!empty($keyList)) {
				
				$sql .= array_shift($keyList);
				$sql .= ',';
				
			}
			
			$sql = substr_replace($sql, ')', -1, 1);
			
			$sql .= ' values(';
			
			while(!empty($tempKeyList)) {
				
				$key = array_shift($tempKeyList);
				
				if($key == 'has_annex' || $key == 'gender' || $key == 'statu') {

					$sql .= $valueList[$key];
					
				} else {
					
					$sql .= "'" . $valueList[$key] . "'";
					
				}
				
				$sql .= ',';
				
			}
			
			$sql = substr_replace($sql, ')', -1, 1);
			
			return $this->db->sqlQuery($sql);
			
		}


		public function countRecords() {

	        $sql = 'select count(*) from resume_info';

	        $resource = $this->db->sqlQuery($sql);

	        $res = mysql_fetch_row($resource);

	        if(!$res) {

                return false;

            }

            return $res[0];

        }


		public function getFullData() {

		    $fd = $this->db->connect();

		    $res = mysql_query('select * from resume_info', $fd);

            if(false !== $res) {

                return $res;

            }

            echo "<script>alert('DataTableModel query error!')</script>";

            return false;

        }
		
		
		//	组合sql语句，进行数据库操作
		public function modify($keyList, $valueList, $id) {
			
			$sql = "update resume_info set ";
			
			while(!empty($keyList)) {
				
				$key = array_shift($keyList);
				
				$sql .= $key . '=';
				
				if($key == 'gender' || $key == 'has_annex') {
				
					$sql .= $valueList[$key];
					
				} else {
					
					$sql .= "'".$valueList[$key]."'";
					
				}
				
				$sql .= ',';
				
			}
			
			$sql = substr_replace($sql, ' ', -1, 1);
			
			$sql .= "where id={$id}";
			
			return $this->db->sqlQuery($sql);
			
		}
		
		
		//	根据id进行查找
		public function select($id) {
			
			$sql = "select * from resume_info where id={$id}";
			
			return $this->db->sqlQuery($sql);
			
		}
		
		
		//	分页查询
		public function pageSelect($limit, $offset) {
			
			$sql = "select * from resume_info limit {$limit} offset {$offset}";
			
			return $this->db->sqlQuery($sql);
			
		}
		
	}
?>